<template>
	<view class="flex column  userDetails width-full">
		<view class="userTitle flex box-sizing  space-between items-center">
			<view class="box-sizing paddingLeft-30" style="width: 120rpx;">
				<u-icon @click="uni.navigateBack()" name="arrow-left" :size="25"></u-icon>
			</view>
			<view style="flex: 1;padding-left: calc(10rpx);" class=" flex box-sizing  flex-center items-center height-full">
				<view class="fontSize-30 weight-700 marginRight-10 text-hidden">
					{{stuentInfo.name+'(学员详情)'}}
				</view>
			</view>
			<view class="right box-sizing paddingRight-50">
				<view class="" style="width: 120rpx; height: 1px;"></view>
			</view>
		</view>
		<view class="crads">
			<u-cell-group :border = "false">
				<u-cell  title="头像" isLink >
					<view class="" style="width: 80rpx;height: 80rpx;border-radius: 50%;overflow: hidden;" slot="value">
						<u-upload
							:fileList="fileList1"
							@afterRead="afterRead"
							:deletable = "false"
							name="1"
							:maxCount="1"
							width="80rpx"
							height="80rpx"
						>
							<u-avatar size = "80rpx" :src="userDetailsInfo.avatar?userDetailsInfo.avatar:src"></u-avatar>
						</u-upload>
					</view>
				</u-cell>
				<u-cell  title="学生姓名" :value="userDetailsInfo.name" ></u-cell>
				<u-cell  title="用户名" :value="userDetailsInfo.username"></u-cell>
				<u-cell  title="座位号" :value="userDetailsInfo.seat"></u-cell>
				<u-cell  title="性别" :value="userDetailsInfo.sex == 1?'男':userDetailsInfo.sex == 2?'女':''"></u-cell>
				<u-cell  title="所属年级" :value="userDetailsInfo.setgrade&&userDetailsInfo.setgrade.name?userDetailsInfo.setgrade.name:''"></u-cell>
				<u-cell  title="就读学校" :value="userDetailsInfo.school"></u-cell>
				<u-cell  title="状态" :value="statusVal[userDetailsInfo.status]"></u-cell>
				<u-cell  title="咨询师" :value="userDetailsInfo.counselor"></u-cell>
				<!-- <u-cell  title="测评师" :value="userDetailsInfo.assessor"></u-cell>
				<u-cell  title="规划师" :value="userDetailsInfo.planner"></u-cell>
				<u-cell  title="学案师" :value="userDetailsInfo.studyplaner"></u-cell>
				<u-cell  title="学法师" :value="userDetailsInfo.methoder"></u-cell> -->
				<u-cell v-if = "userDetailsInfo.px_arr"  v-for="(it,i) in userDetailsInfo.px_arr" :title="it.subject_name" :value="it.px_er" :key = "i"></u-cell>
				
				<u-cell  title="陪伴师" :value="userDetailsInfo.pb_er"></u-cell>
			
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	import userAvatar from '@/static/defaultAvatar.png'
	export default {
		data() {
			return {
				fileList1:[],
				src:userAvatar,
				userDetailsInfo:{},
				stuentInfo:{
					student_id:'',
					name:'',
					learn_mode:''
				},
				statusVal:['','正常','欠费','冻结','结业','退费']
			};
		},
		onLoad(op) {
			this.stuentInfo['name'] = op.name
			this.stuentInfo['student_id'] = op.student_id
			this.stuentInfo['learn_mode'] = op.learn_mode
			this.detail()
		},
		methods:{
			detail(){
				this.$home.detail({student_id:this.stuentInfo['student_id']}).then(res=>{
					this.userDetailsInfo = res
				})
			},
			editAvatar(){
				let that = this
				uni.chooseImage({
					count: 6, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					success: function (res) {
						that.userDetailsInfo.avatar = res.tempFilePaths
					}
				});
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					this.setUpAvatar(result)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: this.$uploadUrl+'Upload/upload', // 仅为示例，非真实的接口地址
						// url: 'http://bbsf.test/api/Upload/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							upload_config_id: 1
						},
						header: {
							token: uni.getStorageSync('token'),
							// 'content-type': 'multipart/form-data'
						},
						success: (res) => {
							resolve(JSON.parse(res.data).data)
						},
						fail:(err)=>{
							// console.log(err,999)
						}
					});
				})
			},
			setUpAvatar(url){
				this.$home.upavatar({student_id:this.userDetailsInfo.student_id,avatar:url}).then((res)=>{
					if(res.status == 200){
						this.userDetailsInfo.avatar = url
						uni.showToast({
							title:'修改成功！',
							icon:'none'
						})
					}else{
						this.fileList1 = []
					}
				})
			}
		}
	}
</script>

<style lang="scss">
.userDetails{
	height: 100vh;
	box-sizing: border-box;
	background-color: #f1f1f1a1;
	
	.userTitle{
		width: 100%;
		height: 120rpx;
		box-sizing: border-box;
		padding-top: var(--status-bar-height);
		// background-color: #fff;
		// border-bottom: 1rpx solid #ededed;
	}
	.crads{
		width: calc(100% - 60rpx);
		margin-top: 30rpx;
		margin-left: 30rpx;
		// height: calc(100vh - 140rpx - 120rpx);
		overflow-y: auto;
		border-radius: 15rpx;
		box-sizing: border-box;
		padding: 0 20rpx 20rpx;
		background-color: #fff;
		margin-bottom: 50rpx;
		.card{
			width: calc(100% - 60rpx);
			color:#333;
		}
	}
}
</style>
